//
//  Nick.cpp
//  dentist
//
//  Created by Denveryee on 13-12-3.
//
//

#include "Nick.h"
#include "BaseBadPoint.h"
#include "BaseTooth.h"
#include "cocos2d.h"

Nick::Nick(void)
{
}

Nick::~Nick(void)
{
	badPoint->autorelease();
}

Nick::Nick(BaseTooth::Position toothKind){
	kind = NICK;
	op = 255;
    fixSpeed = 100;
	scheFlag = true;
    empty = false;
    finishFixed = false;
	switch(toothKind){
		case BaseTooth::UP_LEFT_ONE:
			badPoint = CCSprite::create("img_sr_1280_720_damage_slime_tdirty_30005_png.png");
			badPoint->setPosition(ccp(98,217));
			addChild(badPoint);
			break;
		case BaseTooth::UP_LEFT_TWO:
            badPoint = CCSprite::create("img_sr_1280_720_damage_slime_tdirty_20005_png.png");
			badPoint->setPosition(ccp(122,217));
			addChild(badPoint);
            break;
		case BaseTooth::UP_LEFT_THREE:
			badPoint = CCSprite::create("img_sr_1280_720_damage_slime_tdirty_10005_png.png");
			badPoint->setPosition(ccp(149,217));
			addChild(badPoint);
			break;
		case BaseTooth::UP_LEFT_FOUR:
            badPoint = CCSprite::create("img_sr_1280_720_damage_slime_tdirty_10005_png.png");
			badPoint->setPosition(ccp(179,217));
            badPoint->setFlipX(true);
			addChild(badPoint);
            break;
		case BaseTooth::UP_LEFT_FIVE:
            badPoint = CCSprite::create("img_sr_1280_720_damage_slime_tdirty_20005_png.png");
			badPoint->setPosition(ccp(206,217));
            badPoint->setFlipX(true);
			addChild(badPoint);
            break;
		case BaseTooth::UP_LEFT_SIX:
            badPoint = CCSprite::create("img_sr_1280_720_damage_slime_tdirty_30005_png.png");
			badPoint->setPosition(ccp(230,217));
            badPoint->setFlipX(true);
			addChild(badPoint);
            break;
		case BaseTooth::DOWN_LEFT_ONE:
            badPoint = CCSprite::create("img_sr_1280_720_damage_slime_t3dirty__10005_png.png");
			badPoint->setPosition(ccp(98,179));
			addChild(badPoint);
            break;
		case BaseTooth::DOWN_LEFT_TWO:
            badPoint = CCSprite::create("img_sr_1280_720_damage_slime_t2dirty__10006_png.png");
			badPoint->setPosition(ccp(123,174));
			addChild(badPoint);
            break;
		case BaseTooth::DOWN_LEFT_THREE:
            badPoint = CCSprite::create("img_sr_1280_720_damage_slime_t1dirty__10006_png.png");
			badPoint->setPosition(ccp(150,170));
			addChild(badPoint);
            break;
		case BaseTooth::DOWN_LEFT_FOUR:
            badPoint = CCSprite::create("img_sr_1280_720_damage_slime_t1dirty__10006_png.png");
			badPoint->setPosition(ccp(178,170));
            badPoint->setFlipX(true);
			addChild(badPoint);
            break;
		case BaseTooth::DOWN_LEFT_FIVE:
            badPoint = CCSprite::create("img_sr_1280_720_damage_slime_t2dirty__10006_png.png");
			badPoint->setPosition(ccp(205,173));
            badPoint->setFlipX(true);
			addChild(badPoint);
            break;
		case BaseTooth::DOWN_LEFT_SIX:
            badPoint = CCSprite::create("img_sr_1280_720_damage_slime_t3dirty__10005_png.png");
			badPoint->setPosition(ccp(230,179));
            badPoint->setFlipX(true);
			addChild(badPoint);
            break;
	}
}

bool Nick::fixBadTooth(){
	if(scheFlag){
		schedule(schedule_selector(Nick::remove), 0.1f);
		scheFlag = false;
	}
	return true;
}

void Nick::remove(float dt)
{
    if(badPoint->getOpacity() > 0){
        
        badPoint->setOpacity(op);
        if(badPoint->getOpacity() - fixSpeed > 0)
            op -= fixSpeed;
        else{
            op = 0;
            finishFixed = true;
        }
    }
}

void Nick::stopFix(){
	unschedule(schedule_selector(Nick::remove));
	scheFlag =true;
	CCLOG("scheduler removed");
}